import path from 'path';
import webpack from 'webpack';
import merge from 'webpack-merge';
import HtmlWebpackPlugin from 'html-webpack-plugin';

import pathConfig from '../config/path';
import baseConfig from './webpack.config.base';
import staticConfig from './webpack.config.static';

export default merge.smart(baseConfig, staticConfig, {
  mode: 'development',
  entry: [
    'react-hot-loader/patch',
    'webpack-hot-middleware/client',
    path.join(pathConfig.clientPath, 'csr-client'),
  ],
  output: {
    filename: 'bundle.js',
    path: pathConfig.distPath,
    publicPath: `http://127.0.0.1:${process.env.PORT}/`,
  },
  module: {
    rules: [{
        test: /\.css$/,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1,
              localIdentName: '[name]_[local]--[hash:base64:5]',
              modules: true
            }
          },
          // 'postcss-loader'
        ]
      },
      // {
      //   test: /\.less$/, // antd 中的样式
      //   use: [
      //     'css-loader',
      //     {
      //       loader: 'less-loader',
      //       options: {
      //         paths: [pathConfig.antdPath],
      //         javascriptEnabled: true,
      //         modifyVars: {
      //           'primary-color': '#03b39b'
      //         }
      //       }
      //     }
      //   ]
      // }
    ]
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new HtmlWebpackPlugin({
      inject: true,
      template: path.join(pathConfig.publicPath, 'index.html'),
      favicon: './public/favicon.ico',
    }),
  ]
})
